package br.com.devteam.base.util;

import java.io.IOException;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import com.sun.faces.application.ActionListenerImpl;

public class InterceptException extends ActionListenerImpl implements
		ActionListener {

	@Override
	public void processAction(ActionEvent arg0) throws AbortProcessingException {
		try {
			super.processAction(arg0);
		} catch (Throwable e) {
			e.printStackTrace();
			ExternalContext externalContext = FacesContext.getCurrentInstance()
					.getExternalContext();
			String path = externalContext.getApplicationContextPath();

			try {
				externalContext.redirect(path + "/pages/exception.xhtml");
			} catch (IOException e2) {
				e2.printStackTrace();
			}
		}
	}
}
